# Copyright 1999-2008 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2

inherit eutils 

DESCRIPTION="CouchDb is a distributed document database system with
bi-directional replication."
HOMEPAGE="http://www.couchdb.com/"
SRC_URI="mirror://apache/incubator/couchdb/${PV}-incubating/apache-${P}-incubating.tar.gz"

LICENSE="Apache-2.0"
SLOT="0"
KEYWORDS="~x86 ~amd64"
IUSE=""
RESTRICT="test" #72375

RDEPEND="dev-libs/icu
		dev-lang/erlang
		dev-util/svn2cl"

DEPEND="${RDEPEND}"

#S=${WORKDIR}/${ESVN_PROJECT}

pkg_setup() {
	enewgroup couchdb 
	enewuser couchdb -1 /bin/bash /var/lib couchdb
}

src_compile() {
	econf --with-erlang=/usr/lib/erlang/usr/include --localstatedir="/var"
	emake
}

src_install() {
	# Move put the pidfile in it's own directory for simplicity of ownership
	# Should probably move this up there somewhere and do it before ./configure
	# But I'm lazy.
	sed -i \
		's/COUCHDB_PID_FILE=.*/COUCHDB_PID_FILE=\/var\/run\/couchdb\/couchdb.pid/' \
		etc/default/couchdb.dist

	emake DESTDIR="${D}" install || die "install failed"

	# Yeah there's a better way to do this but I'm lazy, remember?
	mkdir "${D}/var/run/couchdb" -p

	touch "${D}/var/run/couchdb/couchdb.pid"
	chown couchdb:couchdb "${D}/var/run/couchdb"
	chown couchdb:couchdb "${D}/var/run/couchdb/couchdb.pid"
	chown couchdb:couchdb "${D}/var/lib/couchdb"
	chown couchdb:couchdb "${D}/var/log/couchdb"
}
